<?php
namespace app\common\model;

use app\admin\model\File;
use app\admin\model\Pic;
use think\Model;

class Qiniu extends Model{

    public function getPicPath($id=0)
    {
        $result = $this->field('id,path')->find($id);
        return $result['path'];
    }

    /**
     * @param $name
     * @param $path
     * @param $size
     * @param $w
     * @param $h
     * @param $ext
     * @param int $file_type
     * @param int $out
     * @return bool
     */
    public function addNew($name,$path,$size,$w,$h,$ext,$file_type=1,&$out=0){
        if($file_type==1){
            $result = (new Pic())->addNew($name,$path,$ext,$w,$h,$size,'');
        }else{
            $result = (new File())->addNew($name,$path,$ext,$w,$h,$size,'');
        }
        if(!$result){
            $out = '上传失败';
            return false;
        }
        $out = $this->getLastInsID();
        return true;
    }
}